// var animation: WechatMiniprogram.Animation
const innerAudioContext = wx.createInnerAudioContext({
  useWebAudioImplement: true
})
innerAudioContext.src = 'https://kangkangkangkang.oss-cn-wuhan-lr.aliyuncs.com/%E5%BA%B7/index/component/music.mp3'

let MYdata = ""
let dataTemp = ""
var lastId = ""
Page({

  data: {
    MYList: [],
    tempData: "",
    inputData: "功德",
    showData: "",
    classStyle: '',
    value: 0,
    dataTemp: "",
    id: 'default',
    show: false
  },
  userNameInputAction: function (options) {
    var that = this;
    //获取输入框输入的内容
    let value = options.detail.value;
    if (value == '') {
      that.setData({
        inputData: "功德"
      })
    } else {
      that.setData({
        inputData: value
      })
    }

  },
  showBounce: function () {

    var that = this;
    that.setData({
      show: true
    })
  },
  onClose: function () {
    var that = this;
    that.setData({
      show: false
    })
  },


  // 删除是为了避免溢出，因为数据库不可能一直会无限的来进行存储数据
  delData() { //删除数据
    var that = this;
    that.setData({
      inputData: "功德",
      show: false
    })
    this.Delet();
  },
  Delet() {
    wx.showToast({
      title: '删除成功',
      icon: 'success'
    })
  },

  click() {
    //  添加音效---这个是官方文档
    const innerAudioContext = wx.createInnerAudioContext()
    innerAudioContext.autoplay = true
    innerAudioContext.loop = false // 是否循环播放，默认为 false
    innerAudioContext.src = 'https://kangkangkangkang.oss-cn-wuhan-lr.aliyuncs.com/%E5%BA%B7/index/component/music.mp3'
    // ios端音频不能在静音下播放处理
    var music = wx.setInnerAudioOption({
      obeyMuteSwitch: false,
      success: function () {},
      fail: function () {},
    });

    innerAudioContext.onPlay(() => {
      //   console.log('开始播放')
    })
    innerAudioContext.onError((res) => {
      console.log(res.errMsg)
      console.log(res.errCode)
    })
    // 下边是对那些数据的处理
    this.setData({
      classStyle: 'animal',
      id: 'font',
      value: this.data.value + 1
    });

    setTimeout(() => {
      this.setData({
        classStyle: '',
        //id:'default'
      });
    }, 100);
    setTimeout(() => {
      this.setData({
        id: 'default'
      });
    }, 500);
  },
  addData() {
    const inputValue = this.data.inputData;
    console.log(inputValue)

    // 将输入的内容添加到列表中
    this.setData({
      inputData: inputValue,
      show: false
    });
    wx.showToast({
      title: '添加成功',
      icon: 'success',
      duration: 2000 // 持续时间2秒
    });
  }
})